package cn.edu.cug.cs.gtl.renders.openinventor.utils;

import cn.edu.cug.cs.gtl.apis.render.Selector;
import cn.edu.cug.cs.gtl.apis.render.basics.Color;
import cn.edu.cug.cs.gtl.apis.render.nodes.Node;
import cn.edu.cug.cs.gtl.renders.openinventor.basics.ColorImpl;
import com.openinventor.inventor.nodes.SoNode;

import java.util.ArrayList;

public class SelectorImpl extends ArrayList<Node> implements Selector {


    Color selectedColor = new ColorImpl(1.0f,0.0f,0.0f);


    public SelectorImpl(){

    }

    @Override
    public Color getSelectedColor() {
        return selectedColor;
    }

    @Override
    public void setSelectedColor(Color c) {
        selectedColor=c;
    }

    /**
     * 在选择器中查找节点名称为nodeName的节点并返回
     *
     * @param nodeName
     * @return
     */
    @Override
    public Node find(String nodeName) {
        for(Node n : this){
            if(((SoNode)(n.getNativeObject())).getName().equals(nodeName))
                return n;
        }
        return null;
    }

    @Override
    public Node remove(String nodeName) {
        Node r = null;
        for(int i=0;i<this.size();++i){
            r = get(i);
            if(((SoNode)(r.getNativeObject())).getName().equals(nodeName)) {
                remove(i);
                return r;
            }
        }
        return null;
    }


}
